package com.hua.store.web.servlet;

import com.hua.store.domin.Category;
import com.hua.store.domin.PageModel;
import com.hua.store.service.CategoryService;
import com.hua.store.service.ProductService;
import com.hua.store.service.impl.CategoryServiceImpl;
import com.hua.store.service.impl.ProductServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet(name = "AdminProductServlet", urlPatterns = "/AdminProductServlet")
public class AdminProductServlet extends BaseServlet {

    public String findAllProductWithPage(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        int curNum = Integer.parseInt(req.getParameter("num"));
        ProductService service = new ProductServiceImpl();
        PageModel pageModel = service.findAllProductWithPage(curNum);
        req.setAttribute("page", pageModel);
        return "/admin/product/list.jsp";
    }

    public String addProductUI(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        CategoryService service = new CategoryServiceImpl();
        List<Category> allCats = service.getAllCats();
        req.setAttribute("allCats", allCats);
        return "/admin/product/add.jsp";
    }
}
